<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Admin\Controller;


/**
 * 后台展位生成控制器
 * 主要获取展位生成页面聚合数据
 */
class BoothshengchengController extends AdminController {
    
	//展位管理
	public function booth_guanli(){
        $where = array();
        $where  = array('active' => 0);
        if(isset($_GET['name'])){
            $where['name']    =   array('like', '%'.(string)I('name').'%');
        }
		
		$lists = $this->lists('booth_info',$where,'id ');
    	$this->assign('boothguanli',$lists);
	 
	    $this->display();
	}

	//展位申请
    public function booth_apply($customer_name='',$boothname='',$booth_nature='',$address='',$phone='',$contactname='',$tellphone='',$email='',$keyword='',$wechatcode_path='',$website='',$introduction='',$active='',$activedeclare='',$status=''){
		if(IS_POST){
			$boothapply=array('customer_name'=>$customer_name,'boothname'=>$boothname,'booth_nature'=>$booth_nature,'address'=>$address,'phone'=>$phone,'contactname'=>$contactname,'tellphone'=>$tellphone,'email'=>$email,'keyword'=>$keyword,'wechatcode_path'=>$wechatcode_path,'website'=>$website,'introduction'=>$introduction,'active'=>0,'activedeclare'=>$activedeclare,'status'=>0);
			if(!M('Booth_info')->add($boothapply)){
			    echo "<script>alert('展位申请失败！');</script>";
            }else{
                echo "<script>alert('展位申请成功！');</script>";
				
            }

		}
		
	    $this->display();
	}

	//展位编辑
	public function booth_edit($id=0){
		 if(IS_POST){
            $booth_info = D('Booth_info');
            $data = $booth_info->create();
            //var_dump($data);exit;
            if($data){
                if($booth_info->save()!==false){
                    
                    $this->success('更新成功',U('Boothshengcheng/booth_guanli'));
                } else {
                    $this->error('更新失败');
                }
            } else {
                $this->error($booth_info->getError());
            }
		
		 }else {
            $info = array();
            /* 获取数据 */
            $info = M('Booth_info')->find($id);
            $booth = M('Booth_info')->field(true)->select();
            $booth = D('Common/Tree')->toFormatTree($booth);

           $this->assign('info', $info);
            
            $this->display('booth_bianji');
		 }
	}
	//删除
	 public function del(){
        $id = array_unique((array)I('id',0));

        if ( empty($id) ) {
            $this->error('请选择要操作的数据!');
        }

        $where = array('id' => array('in', $id) );
        if(M('Booth_info')->where($where)->delete()){
            $this->success('删除成功');
        } else {
            $this->error('删除失败！');
        }
    }


}




?>